import { NextRequest, NextResponse } from 'next/server'
import { incrementLikes, getLikes } from '@/lib/index'

// 增加点赞数
export async function POST(request: NextRequest) {
  try {
    const { postId } = await request.json()
    
    if (!postId) {
      return NextResponse.json({ error: '缺少文章ID' }, { status: 400 })
    }
    
    await incrementLikes(postId)
    const likes = await getLikes(postId)
    
    return NextResponse.json({ likes })
  } catch (error) {
    console.error('增加点赞失败:', error)
    return NextResponse.json({ error: '服务器错误' }, { status: 500 })
  }
}